# REPLICATION SCRIPT TO RUN GENETIC MATCHING ALGORITHM FOR BIT SIGNING
# 
# Data Input: MatchCollapse.dta
# Data Output: MatchedData.dta

# Set the working directory to that used for the paper.
setwd("INSERT WORKING DIRECTORY HERE")

# Load the Necessary Packages
library(arm)
library(MatchIt)
library(Matching)
library(foreign)

# Read the data into R
bits <- read.dta("MatchCollapse.dta")
attach(bits)

# The following will run a genetic matching algorithm on the collapsed BIT leader
# data and will run matching diagnostics.

matchbits <- matchit(BIT_lead_sign ~ polity + growth + logpop + logrealgdppc + inherited_BITs, data=bits, method="genetic")


summary(matchbits)
matchbits$match.matrix

postscript('jitter.eps', family='AvantGarde')
plot(matchbits, type="jitter")
dev.off()
postscript('hist.eps', family='AvantGarde')
plot(matchbits, type="hist")
dev.off()
postscript('qq%03d.eps', onefile=FALSE, family='AvantGarde')
plot(matchbits, type="QQ")
dev.off()
summary(matchbits)

matchBITs<-match.data(matchbits)

write.dta(matchBITs, file="MatchedData.dta")
